home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’88 / Holey / Holey.p next >
Encoding:
Text File  |  1988-06-23  |  4.0 KB  |  164 lines  |  [TEXT/MPS ]

  1. (*    This is an FKEY that empties the content region of all
  2.     the windows in a layer.  This is useful under MultiFinder
  3.     because you can select icons that might be covered up,
  4.     once all the windows above it become "transparent".
  5.     
  6.     It is a simple variation of the technique described by Greg 
  7.     Marriott in the Oct 87 MacTutor.  It works by modifying
  8.     the strucRgn and contRgn of all the windows, which is a very
  9.     bad thing to do, especially under MultiFinder (where this
  10.     FKEY is most useful.  This puts the FKEY into the category of
  11.     extra-slimey hacks.
  12.  
  13.     The basic routines can be recombined to achieve a variety
  14.     of effects.  (For example, instead of toggling, one FKey
  15.     could make the windows transparent and another restore them.
  16.     
  17.     Note that we do no error checking on the region calculations, 
  18.     so we could crash in low memory situations.
  19.     
  20.  
  21. Known Bugs:
  22.     • In MPW if you activate a transparent window, the  shell
  23.       computes the active region of the window.  Since the window
  24.       is transparent, the region is empty.  If you make the window
  25.       normal, the shell becomes confused until the window is activated
  26.       again.
  27.       
  28.       
  29. MPW Build commands (to make FKEY 9):
  30.  
  31.     Pascal Holey.p -o Holey.p.o 
  32.     link Holey.p.o -o 'Holey FKEY' -rt FKEY=9 -sn Main="Holey" ∂
  33.             "{Libraries}Interface.o" -m 'ENTRYPOINT' ∂
  34.             -t 'FKEY' -c 'FKEY'
  35.             
  36. Larry Rosenstein
  37. *)
  38.  
  39. UNIT Holey;
  40.  
  41. INTERFACE
  42.  
  43. USES
  44.     MemTypes, Quickdraw, OSIntf, ToolIntf;
  45.     
  46. PROCEDURE EntryPoint;
  47.  
  48. IMPLEMENTATION
  49.     
  50.     { Provide a way to call a window defproc given a pointer to it. }
  51. FUNCTION CallWDEF(varCode: INTEGER; theWindow: WindowPtr;
  52.                     message: INTEGER; param: LONGINT;
  53.                     routine: Ptr): LONGINT; INLINE $205F, $4E90;
  54.  
  55.     { Enable the ROM resource map. }
  56. PROCEDURE UseROMMap; INLINE $31FC, $FFFF, $0B9E;
  57.  
  58. PROCEDURE HoleyFKey; FORWARD;
  59.  
  60.     { The main program.  We need this entry point here because
  61.         we use nested procedures.  Otherwise the nested procs
  62.         would be first in the segment. }
  63. PROCEDURE EntryPoint;
  64. BEGIN
  65.     HoleyFKey;
  66. END;
  67.  
  68. PROCEDURE HoleyFKey;
  69.  
  70.     VAR    w:                WindowPeek;
  71.         v:                INTEGER;
  72.         
  73.         savePort:        GrafPtr;
  74.         
  75.         topChange:        WindowPeek;    { topmost windows that changed }
  76.         clobber:        RgnHandle;    { union of all changed windows }
  77.     
  78.     PROCEDURE Setup;            { call this to setup things }
  79.     BEGIN
  80.             { Save the current port }
  81.         GetPort(savePort);
  82.         
  83.             { Init some variables }
  84.         topChange := NIL;
  85.         clobber := NewRgn;
  86.     END;
  87.     
  88.     PROCEDURE WrapUp;            { call this after munging the windows }
  89.     BEGIN
  90.         IF topChange <> NIL THEN { have system refresh things }
  91.             BEGIN
  92.             CalcVisBehind(topChange, clobber);    { cause update events }
  93.             PaintBehind(topChange, clobber);    { refresh window structures }
  94.             END;
  95.         
  96.         DisposeRgn(clobber);
  97.         
  98.         SetPort(savePort);
  99.     END;
  100.     
  101.     PROCEDURE NoteWindow(w: WindowPeek);        { remember info about window }
  102.     BEGIN
  103.         IF topChange = NIL THEN
  104.             topChange := w;
  105.             
  106.         UnionRgn(clobber, w^.strucRgn, clobber);
  107.     END;
  108.     
  109.     PROCEDURE MakeTransparent(w: WindowPeek);
  110.     BEGIN
  111.         WITH w^ DO    { windows are nonrelocatable }
  112.             IF visible THEN    { don't call this on invisible windows }
  113.                 BEGIN
  114.                 NoteWindow(w);
  115.             
  116.                 { make content rgn empty and fix structure rgn accordingly }
  117.                 DiffRgn(strucRgn, contRgn, strucRgn);
  118.                 SetEmptyRgn(contRgn);
  119.                 END;
  120.     END;
  121.     
  122.     PROCEDURE MakeNormal(w: WindowPeek);
  123.     BEGIN
  124.         WITH w^ DO    { windows are nonrelocatable }
  125.             IF visible THEN    { don't call this on invisible windows }
  126.                 BEGIN
  127.             (*
  128.                     { call defproc to recompute regions }
  129.                 UseROMMap;
  130.                 LoadResource(windowDefProc);
  131.                 HLock(windowDefProc);
  132.                 IF CallWDEF(GetWVariant(WindowPtr(w)),
  133.                             WindowPtr(w), wCalcRgns, 0,
  134.                             windowDefProc^) = 0 THEN ;
  135.                 HUnlock(windowDefProc);
  136.             *)
  137.                 WITH grafPort(w)^.portRect DO
  138.                     SizeWindow( windowPtr( w ), right-left, bottom - top , TRUE );
  139.                 NoteWindow(w);
  140.                 END;
  141.     END;
  142.     
  143.     
  144. BEGIN
  145.     Setup;
  146.     
  147.     w := WindowPeek(FrontWindow);
  148.     
  149.         { Loop through all the windows }
  150.     WHILE w <> NIL DO
  151.         BEGIN
  152.             IF EmptyRgn(w^.contRgn) THEN    { already transparent }
  153.                 MakeNormal(w)
  154.             ELSE                             { window is normal }
  155.                 MakeTransparent(w);
  156.                 
  157.             w := w^.nextWindow;
  158.         END;
  159.     
  160.     WrapUp;
  161. END;
  162.  
  163. END.
  164.